package com.dartfar.base.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.jbpm.api.identity.User;

import com.dartfar.organize.model.Department;
import com.dartfar.organize.model.Post;

@Entity
@Table(name = "T_Person")
public class Person implements User {

	private int personId;
	//关联USER
	private T_User t_user;
	//姓名
	private String name;
	//性别
	private String sex;
	//出生年月
	private Date birthday;
	//电话
	private String phone;
	//参加工作时间
	private Date jobDate;
	//所属的班组
	private Department depart;
	//所属岗位
	//private Post post;
	//所拥有的角色
	private Set<Role> roles = new HashSet<Role>();
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public int getPersonId() {
		return personId;
	}
	public void setPersonId(int personId) {
		this.personId = personId;
	}
	
	@OneToOne(mappedBy = "person")
	public T_User getT_user() {
		return t_user;
	}
	
	public void setT_user(T_User t_user) {
		this.t_user = t_user;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public Date getBirthday() {
		return birthday;
	}
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public Date getJobDate() {
		return jobDate;
	}
	public void setJobDate(Date jobDate) {
		this.jobDate = jobDate;
	}

	@ManyToOne
	@JoinColumn(name = "departId")
	public Department getDepart() {
		return depart;
	}
	public void setDepart(Department depart) {
		this.depart = depart;
	}
	
/*	//@ManyToOne(optional = false, fetch=FetchType.LAZY, cascade = {CascadeType.MERGE})
	@ManyToOne
	@JoinColumn(name = "postId")
	//@LazyCollection(LazyCollectionOption.TRUE)
	public Post getPost() {
		return post;
	}
	public void setPost(Post post) {
		this.post = post;
	}*/
	
	@ManyToMany(fetch = FetchType.LAZY,cascade = {CascadeType.MERGE})
	@JoinTable(name = "T_Person_Role",
		joinColumns = {@JoinColumn(name = "personId")},
		inverseJoinColumns = {@JoinColumn(name = "roleId")}
		)
	@LazyCollection(LazyCollectionOption.TRUE)
	public Set<Role> getRoles() {
		return roles;
	}
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	
	
	@Override
	@Transient
	public String getBusinessEmail() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	@Transient
	public String getFamilyName() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	@Transient
	public String getGivenName() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	@Transient
	public String getId() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
}
